﻿
Type DemonBlogVTable
   VTable(4) As Any Ptr
End Type

Type DemonBlog
   pVTable As Any Ptr
End Type

Dim Shared m_VTable As DemonBlogVTable
Dim Shared m_pVTable As any Ptr

Function QueryInterface(This As DemonBlog, riid As Long, pvObj As Long) As Long
   pvObj = 0
   QueryInterface = E_NOINTERFACE
End Function

Function AddRef(This As DemonBlog) As Long
   Return 0
End Function

Function Release(This As DemonBlog) As Long
   Return 0
End Function

Private Function GetUrl(This As DemonBlog, Url As String) As Long
   Url = "http://demon.tw"
   Return 0
End Function

Private Function OpenBlog(This As DemonBlog) As Long
   'ShellExecute 0, "open", "http://demon.tw", 0, 0, 1
   MsgBox "test"
   Return 0
End Function

Public Function InitializeDemonBlog(LE As DemonBlog Ptr) As IUnknown Ptr
   If m_pVTable = 0 Then
      m_VTable.VTable(0) = @QueryInterface
      m_VTable.VTable(1) = @AddRef
      m_VTable.VTable(2) = @Release
      m_VTable.VTable(3) = @GetUrl
      m_VTable.VTable(4) = @OpenBlog
      m_pVTable = @m_VTable
   End If
   LE->pVTable = m_pVTable
   InitializeDemonBlog = Cast(IUnknown Ptr, LE)
End Function
Sub test()
   Dim DB As DemonBlog Ptr=New DemonBlog
   Dim IDB As IUnknown Ptr
   Dim URL As String
   Dim ret As VARIANT
   IDB = InitializeDemonBlog(DB)
   'DispCallFunc(IDB, 12, 1, vbLong, 1, vbLong, cvar(URL), ret)
   DispCallFunc(IDB, 16, 1, vbLong, 0, 0, 0, @ret)
End sub